package com.gitee.vincentzyu.qwq_forge189.commands;

import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.stats.Achievement;
import net.minecraft.stats.AchievementList;
import net.minecraft.util.ChatComponentText;
import net.minecraftforge.fml.common.Mod;


public class CommandCheckAdvancement extends CommandBase {
    @Override
    public String getCommandName(){
        return "qwq_check_advancement";
    }

    @Override
    public String getCommandUsage(ICommandSender sender){
        return "/qwq_check_advancement <player_name>";
    }

    @Override
    public void processCommand(ICommandSender sender, String[] args) throws CommandException{
        if (args.length != 1){
            throw new CommandException("【qwq】指令使用不合法！ 正确用法:" + getCommandUsage(sender));
        }

        String playerName = args[0];
        EntityPlayerMP player = getPlayer(sender, playerName);

        if (player == null){
            throw new CommandException("【qwq】玩家 " + playerName + " 不存在！");
        }

        int cnt = 0;
        for (Achievement achievement: AchievementList.achievementList){
            if ( player.getStatFile().hasAchievementUnlocked(achievement) ){
                cnt++;
                sender.addChatMessage(
                    new ChatComponentText(
                        "【qwq】玩家名：" + playerName + "，完成状态：是， 成就名：" + achievement.getStatName().getUnformattedText()
                    )
                );
            } else {
                sender.addChatMessage(
                    new ChatComponentText(
                        "【qwq】玩家名：" + playerName + "，完成状态：否， 成就名：" + achievement.getStatName().getUnformattedText()
                    )
                );
            }
        }
    }
}
